﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using XNAGameFeatures.Input;

namespace XNAGameFeatures.BasicGame.Screens
{
    /// <summary>
    /// Base class for all screen in the game
    /// Use in the <see cref="ScreenManager"/>
    /// </summary>
    public abstract class Screen : IGameObject
    {

        #region Fields

        /// <summary>
        /// Gets or sets the screen manager.
        /// </summary>
        public ScreenManager ScreenManager { get; set; }

        internal bool IsContentLoaded { get; set; }

        protected List<IGameObject> Objects = new List<IGameObject>();

        #endregion

        #region Boucle

        /// <summary>
        /// Draws the game object content.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        public virtual void Draw(GameTime gameTime)
        {
            if (Objects != null)
            {
                foreach (var gameObject in Objects)
                {
                    gameObject.Draw(gameTime);
                }
            }
        }

        /// <summary>
        /// Loads the content.
        /// </summary>
        public virtual void LoadContent()
        {
            if (Objects != null)
            {
                foreach (var gameObject in Objects)
                {
                    gameObject.LoadContent();
                }
            }
        }

        /// <summary>
        /// Unloads the content.
        /// </summary>
        public virtual void UnloadContent()
        {
            if (Objects != null)
            {
                foreach (var gameObject in Objects)
                {
                    gameObject.UnloadContent();
                }
            }
        }

        /// <summary>
        /// Updates the game object content.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        public virtual void Update(GameTime gameTime)
        {
            if (Objects != null)
            {
                foreach (var gameObject in Objects)
                {
                    gameObject.Update(gameTime);
                }
            }
        }

        /// <summary>
        /// Catch all input entry and manage them.
        /// </summary>
        /// <param name="input">The input.</param>
        public virtual void HandleInput(InputManager input)
        {
            if (Objects != null)
            {
                foreach (var gameObject in Objects)
                {
                    gameObject.HandleInput(input);
                }
            }
        }

        #endregion

    }
}
